using Cysharp.Threading.Tasks;
using GameFramework.Network;
using GameFramework.Request;

namespace GameFramework.GameServer
{
    /// <summary>
    /// 游戏服务器交互服务拓展
    /// </summary>
    public static class GameServerServiceExtensions
    {
        /// <summary>
        /// 向游戏服务器发送请求 并指定应答包类型 若应答包类型不匹配则会返回对应的错误码
        /// </summary>
        public static UniTask<T> SendAsync<T>(this IGameServerService service, Packet packet) where T : IResponse, new()
        {
            return service.SendAsync(packet).ParseResponse<T>();
        }

        /// <summary>
        /// 向游戏服务器发送请求 并等待返回
        /// </summary>
        public static UniTask<IResponse> SendToGameServer(this Packet packet)
        {
            return GameServerService.That.SendAsync(packet);
        }
        
        /// <summary>
        /// 向游戏服务器发送请求 并指定应答包类型 若应答包类型不匹配则会返回对应的错误码
        /// </summary>
        public static UniTask<T> SendToGameServer<T>(this Packet packet) where T : IResponse, new()
        {
            return GameServerService.That.SendAsync<T>(packet);
        }
    }
}